package com.migo.controller;

import com.migo.entity.SysUserEntity;
import com.migo.entity.TechnicalSupportEntity;
import com.migo.service.SysUserService;
import com.migo.service.TechnicalSupportService;
import com.migo.utils.PageUtils;
import com.migo.utils.Query;
import com.migo.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.migo.utils.ShiroUtils.getUserId;


/**
 * 技术支持
 * 
 * @author powervision
 * @email wes.wang@powervision.me
 * @date 2018-12-18 12:22:40
 */
@RestController
@RequestMapping("technicalsupport")
public class TechnicalSupportController {
	@Autowired
	private TechnicalSupportService technicalSupportService;

	@Autowired
	private SysUserService sysUserService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("technicalsupport:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TechnicalSupportEntity> technicalSupportList = technicalSupportService.queryList(query);
		int total = technicalSupportService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(technicalSupportList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("technicalsupport:info")
	public R info(@PathVariable("id") Integer id){
		TechnicalSupportEntity technicalSupport = technicalSupportService.queryObject(id);
		return R.ok().put("technicalSupport", technicalSupport);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("technicalsupport:save")
	public R save(@RequestBody TechnicalSupportEntity technicalSupport){
		SysUserEntity user = sysUserService.queryObject(getUserId());
		technicalSupport.setAddUser(user.getUsername());
		technicalSupportService.save(technicalSupport);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("technicalsupport:update")
	public R update(@RequestBody TechnicalSupportEntity technicalSupport){
		technicalSupportService.update(technicalSupport);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("technicalsupport:delete")
	public R delete(@RequestBody Integer[] ids){
		technicalSupportService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
